package org.tinygroup.template.interpret.terminal;

import java.io.IOException;
import java.io.Writer;

import org.antlr.v4.runtime.tree.TerminalNode;
import org.tinygroup.template.TemplateContext;
import org.tinygroup.template.interpret.TemplateInterpreter;
import org.tinygroup.template.interpret.TerminalNodeProcessor;
import org.tinygroup.template.interpret.TinyAnltrParseConstants;
import org.tinygroup.template.parser.grammer.TinyTemplateParser;

/**
 * Created by luog on 15/7/17.
 */
public class TextPlainNodeProcessor implements TerminalNodeProcessor<TerminalNode> {


  public int getType() {
    return TinyTemplateParser.TEXT_PLAIN;
  }

  public boolean processChildren() {
    return false;
  }

  public Object process(TerminalNode terminalNode, TemplateContext context, Writer writer)
      throws IOException {
    if (context.get(TinyAnltrParseConstants._STOP_EXIT) != null) {
      return null;
    } else {
      TemplateInterpreter.write(writer, terminalNode.getText());
    }
    return null;
  }
}
